module.exports = class extends saas.controller {
  async index() {

  }

  async methodAction() {
    return this.success(this.method);
  }

  async paramsAction() {
    console.log(this.get)
    return this.success(this.get());
  }

  async urlAction() {
    console.log(this.request.raw);
    return this.success(this.request.raw.originalUrl)
  }

  async uniacid_payNotifyActionDynamic() {
    console.log(this.request.params)
    return this.success(this.request.params);
  }

  async ipsAction() {
    return this.success(this.ip);
  }

  async redisAction() {
    const {redis} = saas.app;
    // redis.lpush('store',saas.datetime(Date.now(),'YYYY-MM-dd HH:mm:ss'));
    const len = await redis.llen('store');
    const orderList = [];
    for (let i = 0; i < len; i++) {
      orderList.push(await redis.rpop('store'))
    }
    return this.success(orderList);
  }

  async redispushAction() {
    const {redis} = saas.app;
    redis.lpush('store',saas.datetime(Date.now(),'YYYY-MM-dd HH:mm:ss'));
    return this.success();
  }

  async mqdelayAction() {
    const time = this.request.query.time;
    saas.mq.sendDelayMsg('exDelayed', 'delaytestq', time.toString(), time);
    return this.success();
  }

  async mqAction() {
    const notify = {
      type: '2',
      title: '测试标题',
      content: '这是一条测试内容，看看是否能收到',
      clientid: 'd6527a15edff1343b368740a7a763de9'
    }
    saas.mq.sendQueueMsg("paotuinotify", JSON.stringify(notify), err => {
      console.log(err);
    })
    return this.success();
  }

  async mqdlxAction() {
    console.log('发送时间：' + Date.now());
    saas.mq.sendToDLX('ex', 'testQueue', 'exDLX', 'rtDLX', 'hello', 1000 * 10);
    return this.success();
  }

  async cacheAction() {
    await saas.cache('username', 'admin');
    await saas.cache('password', () => {
      return saas.md5('admin')
    });
    await saas.cache('date', () => {
      return Date.now()
    }, 1000 * 10);
    this.success(await saas.cache('username') + await saas.cache('password') + saas.datetime(await saas.cache('date'), 'YYYY-MM-DD HH:mm:ss'));
  }

  async listAction() {
    // this.reply.display();
    // console.log(saas.app.display());
    // const data = await this.mysql('cmswing_cart').select();
    // this.success(this.request.raw.url);
    saas.grpcClient.UserService.get({userId: 1}, function (err, msg) {
      console.log(err, msg);
    });
    const fn = saas.promisify(saas.grpcClient.UserService.get, saas.grpcClient.UserService);
    const data = await fn({userId: 1});
    this.success(data);
  }

  async getActionGET() {

  }

  async updateActionPOST() {

  }
}
